/**
 * Project Name:fire-industry-DM-center
 * File Name:ConverterCompany.java
 * Package Name:com.firestone.converters.company
 * Date:2018年4月12日下午5:46:45
 *
*/

package com.firestone.converters.company;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;

import com.firestone.bean.entity.elasticsearch.dm.DmMapProject;
import com.firestone.bean.entity.elasticsearch.im.DmImProject;
import com.firestone.bean.vo.BaseListVO;
import com.firestone.bean.vo.company.MapListVO;

/**
 * @Description: TODO(企业控制器视图转换)
 * @author CAIYJ
 * @date 2018年4月12日 下午5:46:45
 */
public final class ConverterCompany {

    /**
     * @Description: TODO(企业仓库列表模型转换)
     * @param dmPage
     * @param imPage
     * @return
     * @author CAIYJ
     * @date 2018年4月13日 上午9:58:05
     * @lastModifier CAIYJ
     */
    public static final BaseListVO<MapListVO> convertMapListVO(
            Page<DmMapProject> dmPage, Page<DmImProject> imPage) {
        BaseListVO<MapListVO> vo = new BaseListVO<>();
        if (dmPage != null) {
            vo.setCount(dmPage.getTotalElements());
            Set<String> set = new HashSet<>();
            if (imPage != null && imPage.hasContent()) {
                for (DmImProject im : imPage.getContent()) {
                    set.add(im.getId());
                }
            }
            if (dmPage.getContent() != null && dmPage.getContent().size() > 0) {
                List<MapListVO> list = new ArrayList<>();
                MapListVO map = null;
                for (DmMapProject dm : dmPage.getContent()) {
                    map = new MapListVO();
                    BeanUtils.copyProperties(dm, map);
                    if (set.contains(dm.getId())) {
                        map.setHasExist(true);
                    }
                    map.setArea(dm.getAddress_area());
                    map.setCity(dm.getAddress_city());
                    map.setCountry(dm.getAddress_country());
                    map.setProvince(dm.getAddress_province());
                    map.setMainBusiness(dm.getMain_business());
                    list.add(map);
                }
                vo.setList(list);
            }
        }
        return vo;
    }
}
